You can make rating with all shipping providers at once. Each shipping provider has the same common
parts with their services, packagaing or COD Payment for example. So it is possible to make rating for all
shipping providers with the same service code and packaging type. For example, all you need to know
about rates is how much it will cost with DHL and USPS. With this information you can simply compare
price results. Here is an example how to get rates from all providers using Express service and envelope
package. All you need to set is service, sender and recipient addresses and/or packaging type and some
information related to each provider.
Code example:
using System;
using System.Collections.Generic;
using SupremeShipping.Objects;
using SupremeShipping.DHL;
using SupremeShipping.USPS;
using SupremeShipping.UPS;
using SupremeShipping.FedEx;
using SupremeShipping.Errors;
/*make an instance of rating*/
RateProvider rate = new RateProvider ();
/* set authorization inforamation realated to given shipper */
rate.DHLAuthTicket = new DHLAuthTicket("user id", "password", "account number ", "shipping key",
"intl shipping key");
rate.USPSAuthTicket = new USPSAuthTicket("user id", "password");
rate.UPSAuthTicket = new UPSAuthTicket("your access license number", "user id", "your password");
rate.FedExAuthTicket = new FedExAuthTicket("customer transction id", "account number", "meter
number");
/* make an instance of rate request */
RateRequest request = new RateRequest();
/* set packaging type to envelope */
request.Packaging = Packaging.Envelope;
/* set service code to express */
request.ServiceCode = ServiceCode.Express;
/* from where */
Address originAdress = new Address();
originAdress.Country = "US";
originAdress.PostalCode = "30076";
request.OriginAddress = originAdress;
/* destination adress */
Address destinationAdress = new Address();
destinationAdress.Country = "US";
destinationAdress.PostalCode = "30077";
request.DestinationAddress = destinationAdress;
/* usually this is from today + n days */
request.ShipDate = new DateTime(2007, 6, 20);
/* weight unit and value */
request.Weight = new Weight(1.00m, WeightUnit.LBS);
/* assging raterequest to rater */
rate.Request = request;
rate.ValidateRequests = false;
/* iterate through responses and get more info. */
List<RateResponse> responses = rate.Check();
foreach (RateResponse response in responses)
{
/* which shipper it is */
string provider = response.Provider.ToString();
if (response.Errors != null && response.Errors.Count > 0)
{
//your error handling mechanism here
}
else
{
foreach(ServicePricing servicePricing in response.Services)
{
string packaging = servicePricing.Packaging;
string serviceCode = servicePricing.ServiceCode;
/*total service cost (surcharges)*/
Money totalCost = servicePricing.TotalPrice;
}
}
}