Common rating covers only common subset of functionalities of all providers. If you want to use UPS specific functionality like COD delivery, TODO you need to use UPSRateProvider:

 

UPSRateProvider provider = new UPSRateProvider();

 

To UPS Check() method you pass three parameteres:

 

  1. UPSAuthTicket object representing authentication information

 

UPSAuthTicket ticket = new UPSAuthTicket("access license number", "user id", "password");

 

  1. UPSRateRequest object representing rate options

 

UPSRateRequest request = new UPSRateRequest();

 

  1. Boolean value indicating whether you want to validate request before sending it to UPS.

 

UPSRateRequest class contains all kind of options handled by UPS. Structure of this class corresponds to raw UPS XML data structures. It gives you the posibility to make use of all UPS features in easy and convenient way.  

 

To make the simplest rate request you need to fill UPSRateRequest object:

 

  1. Create new UPSRateShipment representing your shipment:

 

UPSRateShipment shipment = new UPSRateShipment();

      request.Shipment = shipment;

 

  1. Fill your shipment details: 

 

    1. Original address: 

 

shipment.ShipFrom = new UPSShipFrom();

          shipment.ShipFrom.Address = new UPSAddress();

         shipment.ShipFrom.Address.PostalCode = "33131";

                // ...

 

    1. Destination address: 

 

shipment.ShipTo= new UPSShipFrom();

          shipment.ShipTo.Address = new UPSAddress();

         shipment.ShipTo.Address.PostalCode = "12345";

              // ...

 

    1. Service type: 

 

shipment.Service = new UPSService( UPSServiceCode.Ground );

 

    1. Fill your package details: 

 

UPSPackage package = new UPSPackage();

          shipment.Package = package;

         package.PackagingType = new UPSPackaging(UPSPackagingCode.UPSLetter);

 

That's all. You specifed what and where you want to send your package. And now you can rate it:

 

        UPSRateResponse response = provider.Check(ticket, request, true);

 

And check the rate: 

 

        decimal charge = response.Shipments[0].TotalCharges.MonetaryValue;

 

That was the simplest rate request. You use UPS specific provider to do more sophisticated requests: 

 

  1. Ask for rating for all available services:

 

request.Header.RequestOption = UPSRateRequestOption.Shop; //now there's no need to specify service

 

  1. Specify pickup details: 

 

request.Pickup = new UPSPickup(UPSPickupCode.DailyPickup);

request.Shipment.PickupDate = DateTime.Today;

 

  1. Specify shipment weight: 

 

request.Shipment.ShipmentWeight = new UPSWeight(10); //LBS by default

request.Shipment.ShipmentWeight = new UPSWeight(12, UPSWeightUnitCode.KGS); //or use KGS

 

  1. Ask to be notified about delivery events: 

 

request.Shipment.ServiceOptions = new UPSShipmentServiceOptions(); // do it only once

        UPSNotification notification = new UPSNotification();

      request.Shipment.ServiceOptions.Notification = notification;

notification.NotificationCode = UPSNotificationCode.QVNDeliveryNotification;

      UPSEmailMessage mail= new UPSEmailMessage();

      notification.EmailMessage = mail;

      mail.EmailAddresses = new List<string>();

      mail.EmailAddresses.Add("support@supremetracking.com");

      mail.FromName = "John Doe";

      mail.Subject = "Your package has been delivered";

 

  1. Insure        your pacakge for customs value:

 

request.Shipment.ServiceOptions = new UPSShipmentServiceOptions(); // do it only once

      request.Shipment.ServiceOptions.InsuredValue = new UPSMoney(12);

 

  1. Ask for cash on delivery option: 

 

request.Shipment.ServiceOptions = new UPSShipmentServiceOptions(); // do it only once

UPSCOD cod = new UPSCOD();

      request.Shipment.ServiceOptions.COD = cod;

      cod.CODAmount = new UPSMoney(12);

      cod.CODFundsCode = UPSCODFundsCode.AllFundsAllowed;