Making a Rate Request


In many circumstances, you may want to check the rate for a single shipping type, rather than the rates for all available types by making a FDXRateRequest request. The format and required information is similar to the previous call.

The request will take a format similar to this:

 <?xml version="1.0" encoding="UTF-8" ?>   <FDXRateRequest 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>   <Service>PRIORITYOVERNIGHT</Service>   <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> </FDXRateRequest> XMLREQUEST; 

The main change here is the addition of the Service element (which can optionally be included with the FDXRateAvailableServicesRequest request shown previously, making it very similar to this request), and allowing you to select the service type you would like a quote for.

The code to execute the request and show the result of the request looks like this:

 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); echo "It would cost \${$response->EstimatedCharges->DiscountedCharges->NetCharge}     to mail the package"; echo "<pre>"; print_r(callFedEx($request)); echo "</pre>"; 

And the raw response looks like this:

 <?xml version="1.0" encoding="UTF-8"?> <FDXRateReply xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">   <ReplyHeader>     <CustomerTransactionIdentifier>1</CustomerTransactionIdentifier>   </ReplyHeader>   <EstimatedCharges>     <RateScale>01486</RateScale>     <RateZone>2</RateZone>     <CurrencyCode>USD</CurrencyCode>     <BilledWeight>10.0</BilledWeight>     <DiscountedCharges>       <BaseCharge>26.05</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <Surcharges>       <Fuel>3.00</Fuel>       <Other>0.00</Other>       </Surcharges>       <TotalSurcharge>3.00</TotalSurcharge>       <NetCharge>29.05</NetCharge>       <TotalRebate>0.00</TotalRebate>     </DiscountedCharges>     <ListCharges>       <BaseCharge>26.05</BaseCharge>       <TotalDiscount>0.00</TotalDiscount>       <Surcharges>       <Fuel>3.00</Fuel>       <Other>0.00</Other>       </Surcharges>       <TotalSurcharge>3.00</TotalSurcharge>       <NetCharge>29.05</NetCharge>       <TotalRebate>0.00</TotalRebate>     </ListCharges>     <EffectiveNetDiscount>0.00</EffectiveNetDiscount>   </EstimatedCharges>   <SignatureOption>NONE</SignatureOption> </FDXRateReply> 

As you can see, the response here is very similar to the previous request, the key difference being that you receive a quote for a single service type. The relevant output would simply be this:

 It would cost $29.05 to mail the package 




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