Skip to content

Latest commit

 

History

History
77 lines (52 loc) · 2.27 KB

readme.markdown

File metadata and controls

77 lines (52 loc) · 2.27 KB

DotNetShipping

.NET wrapper to UPS, FedEx, and USPS APIs. Use it to retrieve shipping rates from these carriers.

How to Install

Available in the NuGet Gallery:

PM> Install-Package DotNetShipping

How to Build

git clone https://github.com/kylewest/DotNetShipping.git
cd DotNetShipping
./build.bat

How to Use

NameValueCollection appSettings = ConfigurationManager.AppSettings;

// You will need a license #, userid and password to utilize the UPS provider.
string upsLicenseNumber = appSettings["UPSLicenseNumber"];
string upsUserId = appSettings["UPSUserId"];
string upsPassword = appSettings["UPSPassword"];

// You will need an account # and meter # to utilize the FedEx provider.
string fedexKey = appSettings["FedExKey"];
string fedexPassword = appSettings["FedExPassword"];
string fedexAccountNumber = appSettings["FedExAccountNumber"];
string fedexMeterNumber = appSettings["FedExMeterNumber"];

// You will need a userId to use the USPS provider. Your account will also need access to the production servers.
string uspsUserId = appSettings["USPSUserId"];

// Setup package and destination/origin addresses
var packages = new List<Package>();
packages.Add(new Package(12, 12, 12, 35, 150));
packages.Add(new Package(4, 4, 6, 15, 250));

var origin = new Address("", "", "06405", "US");
var destination = new Address("", "", "20852", "US"); // US Address

// Create RateManager
var rateManager = new RateManager();

// Add desired DotNetShippingProviders
rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUserId, upsPassword));
rateManager.AddProvider(new FedExProvider(fedexKey, fedexPassword, fedexAccountNumber, fedexMeterNumber));
rateManager.AddProvider(new USPSProvider(uspsUserId));

// (Optional) Add RateAdjusters
rateManager.AddRateAdjuster(new PercentageRateAdjuster(.9M));

// Call GetRates()
Shipment shipment = rateManager.GetRates(origin, destination, packages);

// Iterate through the rates returned
foreach (Rate rate in shipment.Rates)
{
	Console.WriteLine(rate);
}

See the sample app in this repository for a working example.

Credits

Originally forked from dotNETShipping.