Skip to content

piyushkp/ShippingInfo

Repository files navigation

Shipping Rate

Installation:

gem install ShippingInfo

1. Fedex

For more information visit Fedex Web Services for Shipping. This will use FEDEX API to get the shipment information, you will need a Fedex developer/production credentials.

   Use Shipping_Info method. 
   def Shipping_Info (fromZipCode, toZipCode, weight)

where fromZipCode => source zipcode, toZipCode => destination zipcode, and weight => package weight in LB

Usage example:

Define the shipper:

shipper = { :name => "Sender",
            :company => "Catprint",
            :phone_number => "555-555-5555",
            :address => "None",
            :city => "None",
            :state => "#{fromState}",
            :postal_code => "#{fromZipCode}",
            :country_code => "US" 
          }

Define the recipient:

recipient = { :name => "Recipient",
              :company => "Company",
              :phone_number => "555-555-5555",
              :address => "Main Street",
              :city => "None",
              :state => "#{toState}",
              :postal_code => "#{toZipCode}",
              :country_code => "US",
              :residential => "false" 
            }

Define the packages; multiple packages in a single shipment are allowed: Note that all the dimensions must be integers.

packages = []
packages << {
  :weight => {:units => "LB", :value => 2},
  :dimensions => {:length => 10, :width => 5, :height => 4, :units => "IN" }
}
packages << {
  :weight => {:units => "LB", :value => 6},
  :dimensions => {:length => 5, :width => 5, :height => 4, :units => "IN" }
}

By default packaging type is "YOUR PACKAGING" and the drop off type is "REGULAR PICKUP". If you need something different you can pass an extra hash for shipping details

shipping_details = {
  :packaging_type => "YOUR_PACKAGING",
  :drop_off_type => "REGULAR_PICKUP"
}

Create a Fedex::Shipment object using your FedEx credentials; mode should be either production or development depending on what Fedex environment you want to use.

require 'fedex'
fedex = Fedex::Shipment.new(:key => 'xxx',
                            :password => 'xxxx',
                            :account_number => 'xxxx',
                            :meter => 'xxx',
                            :mode => 'production')

** Getting Shipping Rates **

To find a shipping rate:

rate = fedex.rate(:shipper=>shipper,
                  :recipient => recipient,
                  :packages => packages,
                  :service_type => "FEDEX_GROUND",
                  :shipping_details => shipping_details)

Fedex provides multiple total values; total_net_charge is the final amount you are looking for.

    $ rate.total_net_charge => "34.03"
    # Complete response
    $ <Fedex::Rate:0x1019ba5f8
          @total_net_charge="34.03",
          @total_surcharges="1.93",
          @total_billing_weight="8.0 LB",
          @total_taxes="0.0",
          @rate_type="PAYOR_ACCOUNT_PACKAGE",
          @total_base_charge="32.1",
          @total_freight_discounts=nil,
          @total_net_freight="32.1",
          @rate_zone="51">

** Getting Transit Time **

Get the Transit Time by

ship = fedex.ship(:shipper=>shipper,
                  :recipient => recipient,
                  :packages => packages,
                  :service_type => "FEDEX_GROUND",
                  :shipping_details => shipping_details)
 
puts ship[:completed_shipment_detail][:operational_detail] [:transit_time]

2. UPS

UPS shipping information, get UPS shipping rate and transit time.

access_options = {  :access_license_number => '9CA349F0CB25A9DB',
                    :user_id => 'piyushkp',
                    :password => 'Admin123#',
                    :order_cutoff_time => 17 ,
                    :sender_city => 'None',
                    :sender_state => Fedex::UpsInfo.state_from_zip("#{fromZipCode}"),
                    :sender_zip => "#{fromZipCode}",
                    :sender_country_code => 'US'
                  }
  
request_options = { :total_packages => 1,
                    :unit_of_measurement => 'LBS',
                    :weight => 10,
                    :city => 'None',
                    :state => Fedex::UpsInfo.state_from_zip("#{toZipCode}"),
                    :zip => "#{toZipCode}",
                    :country_code => 'US',
                    :mode => 'test'
                  }
  
upsInfo = Fedex::UpsInfo.new(access_options)

"UPS Price" => upsInfo.getPrice(request_options)
"UPS GND Transit days" => upsInfo.getTransitTime(request_options)

3. US Post Office (Under development)

Contributors:

Copyright/License:

Copyright 2012 Piyush Patel

This gem is made available under the MIT license.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages