Determining Which Services Are Available


FedEx offers a number of shipping services with different delivery guarantees and targeted distances (domestic, international, and so on). To determine which services are available for a given shipment, and the associated costs and delivery dates, you use the FDXRateAvailableServicesRequest call.

Before actually making the call, an array is set up containing a visually attractive version of all FedEx's shipping services:

 $serviceOptions = array(); $serviceOptions['PRIORITYOVERNIGHT'] = "Priority Overnight"; $serviceOptions['STANDARDOVERNIGHT'] = "Standard Overnight"; $serviceOptions['FIRSTOVERNIGHT'] = "First Overnight"; $serviceOptions['FEDEX2DAY'] = "Two Day"; $serviceOptions['FEDEXEXPRESSSAVER'] = "Express Saver"; $serviceOptions['INTERNATIONALPRIORITY'] = "International Priority"; $serviceOptions['INTERNATIONALECONOMY'] = "International Economy"; $serviceOptions['INTERNATIONALFIRST'] = "International First"; $serviceOptions['FEDEX1DAYFREIGHT'] = "One Day Freight"; $serviceOptions['FEDEX2DAYFREIGHT'] = "Two Day Freight"; $serviceOptions['FEDEX3DAYFREIGHT'] = "Three Day Freight"; $serviceOptions['FEDEXGROUND'] = "Ground"; $serviceOptions['GROUNDHOMEDELIVERY'] = "Ground Home Delivery"; $serviceOptions['INTERNATIONALPRIORITY FREIGHT'] = "International Priority   Freight"; $serviceOptions['INTERNATIONALECONOMY FREIGHT'] = "International Economy Freight"; $serviceOptions['EUROPEFIRSTINTERNATIONALPRIORITY'] = "Europe First International   Priority"; 

This will be used to convert the response into data that can be shown to an end user.

The call will look something like this:

 $request = <<< XMLREQUEST <?xml version="1.0" encoding="UTF-8" ?>   <FDXRateAvailableServicesRequest xmlns:api="http://www.fedex.com/fsmapi"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:noNamespaceSchemaLocation="FDXRateRequest.xsd">   <RequestHeader>     <CustomerTransactionIdentifier>1</CustomerTransactionIdentifier>     <AccountNumber>$accountNumber</AccountNumber>     <MeterNumber>$meterNumber</MeterNumber>     <CarrierCode>$carrier</CarrierCode>   </RequestHeader>   <ShipDate>2006-04-17</ShipDate>   <DropoffType>REGULARPICKUP</DropoffType>   <Packaging>FEDEXBOX</Packaging>   <WeightUnits>LBS</WeightUnits>   <Weight>10.0</Weight>   <ListRate>1</ListRate>   <OriginAddress>     <StateOrProvinceCode>DC</StateOrProvinceCode>     <PostalCode>20500</PostalCode>     <CountryCode>US</CountryCode>   </OriginAddress>   <DestinationAddress>     <StateOrProvinceCode>DC</StateOrProvinceCode>     <PostalCode>20310-6605</PostalCode>     <CountryCode>US</CountryCode>   </DestinationAddress>   <Payment>     <PayorType>SENDER</PayorType>   </Payment>   <PackageCount>1</PackageCount> </FDXRateAvailableServicesRequest> XMLREQUEST; 

The CarrierCode element allows you to indicate whether FedEx Express (FDXE) or FedEx Ground (FDXG) will be used to handle the shipment. The examples in this chapter all deal with FedEx Express. The main difference programmatically (apart from the CarrierCode) is that while Express shipments are accepted and processed individually automatically, Ground shipments must be closed (with a separate call) before being considered complete, and cannot be canceled or deleted once that close call is made.

DropOffType indicates how FedEx will obtain the package. Valid tokens are as follows:

  • REGULARPICKUP — FedEx will pick up the package during a regularly scheduled pickup (most businesses schedule a regular pickup time).

  • REQUESTCOURIER — A courier will be dispatched to pick up the package on the requested day.

  • DROPBOX — The item will be deposited in a FedEx drop box.

  • BUSINESSSERVICECENTER — The item will be dropped off at a service center.

  • STATION — The item will be dropped off at a FedEx station.

Packaging indicates what type of package will be used for shipping. FedEx provides its shipping materials free of charge to business customers, so it's a good option. If you use your own packaging, you must instead include the package's dimensions. All of FedEx's shipping materials are clearly labeled with a name that should match one of the items on the list. Order a few of everything to get an idea of what works for your products. Valid tokens are as follows:

  • FEDEXENVELOPE — 8.5×11-inch envelope, holds up to 30 pages

  • FEDEXPAK — Tear-and water-resistant oversized envelope for larger documents

  • FEDEXBOX — One of FedEx's three standard box sizes

  • FEDEXTUBE — Blueprint or poster tube

  • FEDEX10KBOX — Larger corrugated cardboard box (brown)

  • FEDEX25KBOX — Even larger corrugated cardboard box (also brown)

  • YOURPACKAGING — Anything not provided by FedEx

To ship with your own packaging, change the Packaging line to YOURPACKAGING and include the dimensions of your package:

   <Dimensions>     <Length>10</Length>     <Width>4</Width>     <Height>2</Height>     <Units>IN</Units>   </Dimensions> 

The Units element can either be IN for inches or CM for centimeters. U.S. Domestic Express requests must be in inches. Use whole numbers only for both units.

WeightUnits can either be LBS or KGS. Again, U.S. Domestic Express requests require the imperial value, LBS. The Weight value can contain up to one decimal place.

ListRate requests FedEx to return the list rate for the shipment in addition to the discounted rate. In my experience, most stores charge the list rate, and pocket the difference.

Commercial customers doing large volumes of shipping earn discounts on each package they ship, and by default, the API only returns the discounted value. When ListRate is set to 1 (or TRUE), the API will also return the list rate for the shipment.

To execute the call, the response just needs to be passed to the function introduced earlier; in this case, the response is parsed and displayed:

 echo "<h3>Request</h3>\n"; echo "<pre>\n"; print_r(simplexml_load_string($request)); echo "</pre>\n"; echo "<h3>Response</h3>\n"; $response = callFedEx($request); foreach ($response->Entry AS $service) {   echo "It would cost \${$service->EstimatedCharges->DiscountedCharges->NetCharge}     to mail the package with " . $serviceOptions["{$service->Service}"] . ' ';   echo "Which has an estimated delivery date of " . date('l dS \of F',     strtotime($service->DeliveryDate)) . "<br>"; } echo "<pre>"; print_r($response); echo "</pre>"; 

The XML response from the API looks like this:

 <?xml version="1.0" encoding="UTF-8"?> <FDXRateAvailableServicesReply   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <ReplyHeader>   <CustomerTransactionIdentifier>1</CustomerTransactionIdentifier> </ReplyHeader> <entry>   <Service>PRIORITYOVERNIGHT</Service>   <Packaging>FEDEXBOX</Packaging>   <DeliveryDate>2006-04-18</DeliveryDate>   <DeliveryDay>TUE</DeliveryDay>   <DestinationStationID>IAD</DestinationStationID>   <EstimatedCharges>     <DimWeightUsed>false</DimWeightUsed>     <RateScale>01486</RateScale>     <RateZone>2</RateZone>     <CurrencyCode>USD</CurrencyCode>     <BilledWeight>10.0</BilledWeight>     <DimWeight>0.0</DimWeight>     <DiscountedCharges>       <BaseCharge>26.05</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>3.00</TotalSurcharge>       <NetCharge>29.05</NetCharge>       <TotalRebate>0.00</TotalRebate>     </DiscountedCharges>     <ListCharges>       <BaseCharge>26.05</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>3.00</TotalSurcharge>       <NetCharge>29.05</NetCharge>       <TotalRebate>0.00</TotalRebate>     </ListCharges>     <EffectiveNetDiscount>0.00</EffectiveNetDiscount>   </EstimatedCharges>   <SignatureOption>NONE</SignatureOption> </entry> <Entry>   <Service>FEDEX2DAY</Service>   <Packaging>FEDEXBOX</Packaging>   <DeliveryDate>2006-04-19</DeliveryDate>   <DeliveryDay>WED</DeliveryDay>   <DestinationStationID>IAD</DestinationStationID>   <EstimatedCharges>     <DimWeightUsed>false</DimWeightUsed>     <RateScale>05980</RateScale>     <RateZone>2</RateZone>     <CurrencyCode>USD</CurrencyCode>     <BilledWeight>10.0</BilledWeight>     <DimWeight>0.0</DimWeight>     <DiscountedCharges>       <BaseCharge>11.80</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>1.36</TotalSurcharge>       <NetCharge>13.16</NetCharge>       <TotalRebate>0.00</TotalRebate>     </DiscountedCharges>     <ListCharges>       <BaseCharge>11.80</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>1.36</TotalSurcharge>       <NetCharge>13.16</NetCharge>       <TotalRebate>0.00</TotalRebate>     </ListCharges>     <EffectiveNetDiscount>0.00</EffectiveNetDiscount>   </EstimatedCharges>   <SignatureOption>NONE</SignatureOption> </Entry> <Entry>   <Service>STANDARDOVERNIGHT</Service>   <Packaging>FEDEXBOX</Packaging>   <DeliveryDate>2006-04-18</DeliveryDate>   <DeliveryDay>TUE</DeliveryDay>   <DestinationStationID>IAD</DestinationStationID>   <EstimatedCharges>     <DimWeightUsed>false</DimWeightUsed>     <RateScale>01283</RateScale>     <RateZone>2</RateZone>     <CurrencyCode>USD</CurrencyCode>     <BilledWeight>10.0</BilledWeight>     <DimWeight>0.0</DimWeight>     <DiscountedCharges>       <BaseCharge>21.80</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>2.51</TotalSurcharge>       <NetCharge>24.31</NetCharge>       <TotalRebate>0.00</TotalRebate>     </DiscountedCharges>     <ListCharges>       <BaseCharge>21.80</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <TotalSurcharge>2.51</TotalSurcharge>       <NetCharge>24.31</NetCharge>       <TotalRebate>0.00</TotalRebate>     </ListCharges>     <EffectiveNetDiscount>0.00</EffectiveNetDiscount>   </EstimatedCharges>   <SignatureOption>NONE</SignatureOption> </entry> </FDXRateAvailableServicesReply> 

As you can see, after returning the CustomerTransactionIdentifier, the response includes an Entry for each available service type. Each Entry includes the name of the service, delivery date, and both discounted and list charges applicable to the shipment. In this case, because I don't ship that much, no discount is applicable. The applicable output of this script should look something like this:

 It would cost $29.05 to mail the package with Priority Overnight which has an     estimated delivery date of Tuesday 18th of April It would cost $13.16 to mail the package with Two Day which has an estimated     delivery date of Wednesday 19th of April It would cost $24.31 to mail the package with Standard Overnight which has an     estimated delivery date of Tuesday 18th of April 

This tells me that it would cost $29.05 to ship a 10-pound box from the White House to the Pentagon with Priority Overnight shipping (those are the zip codes used in the original request).




Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
Professional Web APIs with PHP. eBay, Google, PayPal, Amazon, FedEx, Plus Web Feeds
ISBN: 764589547
EAN: N/A
Year: 2006
Pages: 130

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net