Search

Using Active Shipping for Shipping Rate Estimates

Stafford Brooke

2 min read

Oct 31, 2011

Using Active Shipping for Shipping Rate Estimates

Active Shipping is a nifty Shipping API extension for Active Merchant. It provides methods for interacting with common shipping carrier APIs. Recently we used Active Shipping on a client’s e-commerce site to provide customers with many shipping options from several carriers.

Getting Rates

To get shipping rates for a carrier, you first need to “package” up some information about what you are shipping. Using the Package class you can build an array of packages. Use each package’s dimensions, weight, and the unit system you are measuring with (this will default to metric) to create a new package. Here in an example package:

From working with Active Shipping and various carrier APIs we have learned that all carriers require a package weight. Some will return results for a package with no dimensions. However, rates will vary greatly depending on the dimensions of your packages, so it is a good idea to always include them so that your rate estimates are accurate.

Along with the array of packages, Active Shipping needs to know some information about the origin and destination of your shipment. Using the Location class you can create an origin and destination location for your shipment. Here is an example of a destination (the origin is built the same way):

The Location class takes country, state, city, and zip. Working with Active Shipping and various carrier APIs we have found you can get away with just using country and zip code if needed.

Once we have an origin, destination, and packages we are ready to make request to the carriers’ APIs. Initialize the carrier you want to you use, then call its find_rates method:

Getting access to carrier APIs.

Each carrier requires its own set of credentials. You can sign up for each carrier’s service on their respective websites. While the UPS codes seem to always “just work”, you will need to pass :test => true as a param to get Fedex to work while you are testing your application. We were unable to get the USPS API to provide rates in test mode). To get the USPS API to provide rates you will need to contact and have your production API access turned on. The best way to do this is the call the number provided in the confirmation email they sent. Requests made via email seem to take a couple days to get processed.

Active Shipping is just one of the great extensions of Active Merchant. What other Active Merchant extensions are you using in your e-commerce sites/development?

Mark Dalrymple

Reviewer Big Nerd Ranch

MarkD is a long-time Unix and Mac developer, having worked at AOL, Google, and several start-ups over the years.  He’s the author of Advanced Mac OS X Programming: The Big Nerd Ranch Guide, over 100 blog posts for Big Nerd Ranch, and an occasional speaker at conferences. Believing in the power of community, he’s a co-founder of CocoaHeads, an international Mac and iPhone meetup, and runs the Pittsburgh PA chapter. In his spare time, he plays orchestral and swing band music.

Speak with a Nerd

Schedule a call today! Our team of Nerds are ready to help

Let's Talk

Related Posts

We are ready to discuss your needs.

Not applicable? Click here to schedule a call.

Stay in Touch WITH Big Nerd Ranch News