|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 3 | +This example shows how to use the FedEx RateRequest service. |
| 4 | +The variables populated below represents the minimum required values. |
| 5 | +You will need to fill all of these, or risk seeing a SchemaValidationError |
| 6 | +exception thrown by suds. |
| 7 | +
|
| 8 | +TIP: Near the bottom of the module, see how to check the if the destination |
| 9 | + is Out of Delivery Area (ODA). |
| 10 | +""" |
| 11 | +import logging |
| 12 | +from example_config import CONFIG_OBJ |
| 13 | +from fedex.services.rate_service import FedexRateServiceRequest |
| 14 | + |
| 15 | +# Set this to the INFO level to see the response from Fedex printed in stdout. |
| 16 | +logging.basicConfig(level=logging.INFO) |
| 17 | + |
| 18 | +# This is the object that will be handling our tracking request. |
| 19 | +# We're using the FedexConfig object from example_config.py in this dir. |
| 20 | +rate_request = FedexRateServiceRequest(CONFIG_OBJ) |
| 21 | + |
| 22 | +rate_request.RequestedShipment.ServiceType = 'FEDEX_FREIGHT' |
| 23 | + |
| 24 | +rate_request.RequestedShipment.DropoffType = 'REGULAR_PICKUP' |
| 25 | + |
| 26 | +rate_request.RequestedShipment.PackagingType = 'YOUR_PACKAGING' |
| 27 | + |
| 28 | +rate_request.RequestedShipment.FreightShipmentDetail.TotalHandlingUnits = 1 |
| 29 | + |
| 30 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightAccountNumber = '510087020' |
| 31 | + |
| 32 | +rate_request.RequestedShipment.Shipper.Address.PostalCode = '72601' |
| 33 | +rate_request.RequestedShipment.Shipper.Address.CountryCode = 'US' |
| 34 | +rate_request.RequestedShipment.Shipper.Address.City = 'Harrison' |
| 35 | +rate_request.RequestedShipment.Shipper.Address.StateOrProvinceCode = 'AR' |
| 36 | +rate_request.RequestedShipment.Shipper.Address.Residential = False |
| 37 | +rate_request.RequestedShipment.Recipient.Address.PostalCode = '72601' |
| 38 | +rate_request.RequestedShipment.Recipient.Address.CountryCode = 'US' |
| 39 | +rate_request.RequestedShipment.Recipient.Address.StateOrProvinceCode = 'AR' |
| 40 | +rate_request.RequestedShipment.Recipient.Address.City = 'Harrison' |
| 41 | + |
| 42 | +#include estimated duties and taxes in rate quote, can be ALL or NONE |
| 43 | +rate_request.RequestedShipment.EdtRequestType = 'NONE' |
| 44 | + |
| 45 | +rate_request.RequestedShipment.PackageDetail = 'PACKAGE_SUMMARY' |
| 46 | + |
| 47 | +rate_request.RequestedShipment.FreightShipmentDetail.PaymentType = 'PREPAID' |
| 48 | + |
| 49 | +# note: in order for this to work in test, you may need to use the |
| 50 | +# specially provided LTL addresses emailed to you when signing up. |
| 51 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.PersonName = 'Sender Name' |
| 52 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.CompanyName = 'Some Company' |
| 53 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Contact.PhoneNumber = '9012638716' |
| 54 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.StreetLines = ['2000 Freight LTL Testing'] |
| 55 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.City = 'Harrison' |
| 56 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.StateOrProvinceCode = 'AR' |
| 57 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.PostalCode = '72601' |
| 58 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.CountryCode = 'US' |
| 59 | +rate_request.RequestedShipment.FreightShipmentDetail.FedExFreightBillingContactAndAddress.Address.Residential = False |
| 60 | + |
| 61 | +spec = rate_request.create_wsdl_object_of_type('ShippingDocumentSpecification') |
| 62 | + |
| 63 | +spec.ShippingDocumentTypes = [spec.CertificateOfOrigin] |
| 64 | + |
| 65 | +rate_request.RequestedShipment.ShippingDocumentSpecification = spec |
| 66 | + |
| 67 | +role = rate_request.create_wsdl_object_of_type('FreightShipmentRoleType') |
| 68 | + |
| 69 | +rate_request.RequestedShipment.FreightShipmentDetail.Role = role.SHIPPER |
| 70 | + |
| 71 | +package1_weight = rate_request.create_wsdl_object_of_type('Weight') |
| 72 | +package1_weight.Value = 500.0 |
| 73 | +package1_weight.Units = "LB" |
| 74 | + |
| 75 | +rate_request.RequestedShipment.FreightShipmentDetail.PalletWeight = package1_weight |
| 76 | + |
| 77 | +package1 = rate_request.create_wsdl_object_of_type('FreightShipmentLineItem') |
| 78 | +package1.Weight = package1_weight |
| 79 | +package1.Packaging = 'PALLET' |
| 80 | +package1.Description = 'Products' |
| 81 | +package1.FreightClass = 'CLASS_500' |
| 82 | + |
| 83 | +rate_request.RequestedShipment.FreightShipmentDetail.LineItems = package1 |
| 84 | + |
| 85 | +# If you'd like to see some documentation on the ship service WSDL, un-comment |
| 86 | +# this line. (Spammy). |
| 87 | +#print rate_request.client |
| 88 | + |
| 89 | +# Un-comment this to see your complete, ready-to-send request as it stands |
| 90 | +# before it is actually sent. This is useful for seeing what values you can |
| 91 | +# change. |
| 92 | +#print rate_request.RequestedShipment |
| 93 | + |
| 94 | +# Fires off the request, sets the 'response' attribute on the object. |
| 95 | +rate_request.send_request() |
| 96 | + |
| 97 | +# This will show the reply to your rate_request being sent. You can access the |
| 98 | +# attributes through the response attribute on the request object. This is |
| 99 | +# good to un-comment to see the variables returned by the FedEx reply. |
| 100 | +#print rate_request.response |
| 101 | + |
| 102 | +# Here is the overall end result of the query. |
| 103 | +print "HighestSeverity:", rate_request.response.HighestSeverity |
| 104 | + |
| 105 | +# RateReplyDetails can contain rates for multiple ServiceTypes if ServiceType was set to None |
| 106 | +for service in rate_request.response.RateReplyDetails: |
| 107 | + for detail in service.RatedShipmentDetails: |
| 108 | + for surcharge in detail.ShipmentRateDetail.Surcharges: |
| 109 | + if surcharge.SurchargeType == 'OUT_OF_DELIVERY_AREA': |
| 110 | + print "%s: ODA rate_request charge %s" % (service.ServiceType, surcharge.Amount.Amount) |
| 111 | + |
| 112 | + for rate_detail in service.RatedShipmentDetails: |
| 113 | + print "%s: Net FedEx Charge %s %s" % (service.ServiceType, rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Currency, |
| 114 | + rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount) |
| 115 | + |
0 commit comments