|
1 | 1 | #!/usr/bin/env python |
2 | 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 |
| 3 | +This example shows how to use the FedEx Service Validation, |
| 4 | +Availability and Commitment Service. |
| 5 | +The variables populated below represents common values. |
| 6 | +You will need to fill out the required values or risk seeing a SchemaValidationError |
6 | 7 | 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 | 8 | """ |
11 | 9 | import logging |
| 10 | +import datetime |
12 | 11 | from example_config import CONFIG_OBJ |
13 | | -from fedex.services.rate_service import FedexRateServiceRequest |
| 12 | +from fedex.services.availability_commitment_service import FedexAvailabilityCommitmentRequest |
14 | 13 |
|
15 | 14 | # Set this to the INFO level to see the response from Fedex printed in stdout. |
16 | 15 | logging.basicConfig(level=logging.INFO) |
17 | 16 |
|
18 | 17 |
|
19 | | -# This is the object that will be handling our tracking request. |
| 18 | +# This is the object that will be handling our service availability request. |
20 | 19 | # We're using the FedexConfig object from example_config.py in this dir. |
21 | | -customer_transaction_id = "*** RateService Request v18 using Python ***" # Optional transaction_id |
22 | | -rate_request = FedexRateServiceRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id) |
23 | | - |
24 | | -# If you wish to have transit data returned with your request you |
25 | | -# need to uncomment the following |
26 | | -# rate_request.ReturnTransitAndCommit = True |
27 | | - |
28 | | -# This is very generalized, top-level information. |
29 | | -# REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER or STATION |
30 | | -rate_request.RequestedShipment.DropoffType = 'REGULAR_PICKUP' |
| 20 | +customer_transaction_id = "*** AvailabilityAndCommitment Request v4 using Python ***" # Optional transaction_id |
| 21 | +avc_request = FedexAvailabilityCommitmentRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id) |
31 | 22 |
|
32 | | -# See page 355 in WS_ShipService.pdf for a full list. Here are the common ones: |
33 | | -# STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, FEDEX_EXPRESS_SAVER |
34 | | -# To receive rates for multiple ServiceTypes set to None. |
35 | | -rate_request.RequestedShipment.ServiceType = 'FEDEX_GROUND' |
| 23 | +# Specify the origin postal code and country code. These fields are required. |
| 24 | +avc_request.Origin.PostalCode = '29631' |
| 25 | +avc_request.Origin.CountryCode = 'US' |
36 | 26 |
|
37 | | -# What kind of package this will be shipped in. |
38 | | -# FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING |
39 | | -rate_request.RequestedShipment.PackagingType = 'YOUR_PACKAGING' |
| 27 | +# Specify the destination postal code and country code. These fields are required. |
| 28 | +avc_request.Destination.PostalCode = '27577' |
| 29 | +avc_request.Destination.CountryCode = 'US' |
40 | 30 |
|
41 | | -# Shipper's address |
42 | | -rate_request.RequestedShipment.Shipper.Address.PostalCode = '29631' |
43 | | -rate_request.RequestedShipment.Shipper.Address.CountryCode = 'US' |
44 | | -rate_request.RequestedShipment.Shipper.Address.Residential = False |
| 31 | +# Can be set to FEDEX_TUBE, YOUR_PACKAGING, FEDEX_BOX etc.. Defaults to YOUR_PACKAGING if not set. |
| 32 | +#avc_request.Packaging = 'FEDEX_ENVELOPE' |
45 | 33 |
|
46 | | -# Recipient address |
47 | | -rate_request.RequestedShipment.Recipient.Address.PostalCode = '27577' |
48 | | -rate_request.RequestedShipment.Recipient.Address.CountryCode = 'US' |
49 | | -# This is needed to ensure an accurate rate quote with the response. |
50 | | -#rate_request.RequestedShipment.Recipient.Address.Residential = True |
51 | | -#include estimated duties and taxes in rate quote, can be ALL or NONE |
52 | | -rate_request.RequestedShipment.EdtRequestType = 'NONE' |
| 34 | +# Can be set to the expected date. Defaults to today if not set. |
| 35 | +#avc_request.ShipDate = datetime.date.today().isoformat() |
53 | 36 |
|
54 | | -# Who pays for the rate_request? |
55 | | -# RECIPIENT, SENDER or THIRD_PARTY |
56 | | -rate_request.RequestedShipment.ShippingChargesPayment.PaymentType = 'SENDER' |
| 37 | +# Can be set to PRIORITY_OVERNIGHT, FEDEX_2_DAY, STANDARD_OVERNIGHT etc.. Defaults to showing all options if not set. |
| 38 | +#avc_request.Service = 'FEDEX_2_DAY' |
57 | 39 |
|
58 | | -package1_weight = rate_request.create_wsdl_object_of_type('Weight') |
59 | | -# Weight, in LB. |
60 | | -package1_weight.Value = 1.0 |
61 | | -package1_weight.Units = "LB" |
62 | | - |
63 | | -package1 = rate_request.create_wsdl_object_of_type('RequestedPackageLineItem') |
64 | | -package1.Weight = package1_weight |
65 | | -#can be other values this is probably the most common |
66 | | -package1.PhysicalPackaging = 'BOX' |
67 | | -# Required, but according to FedEx docs: |
68 | | -# "Used only with PACKAGE_GROUPS, as a count of packages within a |
69 | | -# group of identical packages". In practice you can use this to get rates |
70 | | -# for a shipment with multiple packages of an identical package size/weight |
71 | | -# on rate request without creating multiple RequestedPackageLineItem elements. |
72 | | -# You can OPTIONALLY specify a package group: |
73 | | -# package1.GroupNumber = 0 # default is 0 |
74 | | -# The result will be found in RatedPackageDetail, with specified GroupNumber. |
75 | | -package1.GroupPackageCount = 1 |
76 | | -# Un-comment this to see the other variables you may set on a package. |
77 | | -#print(package1) |
78 | | - |
79 | | -# This adds the RequestedPackageLineItem WSDL object to the rate_request. It |
80 | | -# increments the package count and total weight of the rate_request for you. |
81 | | -rate_request.add_package(package1) |
| 40 | +# Fires off the request, sets the 'response' attribute on the object. |
| 41 | +avc_request.send_request() |
82 | 42 |
|
83 | | -# If you'd like to see some documentation on the ship service WSDL, un-comment |
84 | | -# this line. (Spammy). |
85 | | -#print(rate_request.client) |
| 43 | +# If you'd like to see some documentation on the ship service WSDL, un-comment this line. |
| 44 | +print(avc_request.client) |
86 | 45 |
|
87 | 46 | # Un-comment this to see your complete, ready-to-send request as it stands |
88 | | -# before it is actually sent. This is useful for seeing what values you can |
89 | | -# change. |
90 | | -#print(rate_request.RequestedShipment) |
91 | | - |
92 | | -# Fires off the request, sets the 'response' attribute on the object. |
93 | | -rate_request.send_request() |
94 | | - |
95 | | -# This will show the reply to your rate_request being sent. You can access the |
| 47 | +# before it is actually sent. This is useful for seeing what values you can change. |
| 48 | +#print(avc_request.Origin) |
| 49 | +#print(avc_request.Destination) |
| 50 | +#print(avc_request.ShipDate) |
| 51 | +#print(avc_request.CarrierCode) |
| 52 | +#print(avc_request.Service) |
| 53 | +#print(avc_request.Packaging) |
| 54 | + |
| 55 | +# This will show the reply to your avc_request being sent. You can access the |
96 | 56 | # attributes through the response attribute on the request object. This is |
97 | 57 | # good to un-comment to see the variables returned by the FedEx reply. |
98 | | -#print(rate_request.response) |
| 58 | +#print(avc_request.response) |
99 | 59 |
|
100 | 60 | # Here is the overall end result of the query. |
101 | | -print("HighestSeverity:", rate_request.response.HighestSeverity) |
102 | | - |
103 | | -# RateReplyDetails can contain rates for multiple ServiceTypes if ServiceType was set to None |
104 | | -for service in rate_request.response.RateReplyDetails: |
105 | | - for detail in service.RatedShipmentDetails: |
106 | | - for surcharge in detail.ShipmentRateDetail.Surcharges: |
107 | | - if surcharge.SurchargeType == 'OUT_OF_DELIVERY_AREA': |
108 | | - print("%s: ODA rate_request charge %s" % (service.ServiceType, surcharge.Amount.Amount)) |
109 | | - |
110 | | - for rate_detail in service.RatedShipmentDetails: |
111 | | - print("%s: Net FedEx Charge %s %s" % (service.ServiceType, |
112 | | - rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Currency, |
113 | | - rate_detail.ShipmentRateDetail.TotalNetFedExCharge.Amount)) |
114 | | - |
| 61 | +print("HighestSeverity: {}".format(avc_request.response.HighestSeverity)) |
| 62 | +print("") |
| 63 | + |
| 64 | +# Cycle through all the Notifications |
| 65 | +for notification in avc_request.response.Notifications: |
| 66 | + print("Notification:") |
| 67 | + print("Severity {} Source {}".format(notification.Severity, notification.Source)) |
| 68 | + if hasattr(notification, 'Code'): |
| 69 | + print("Code {}".format(notification.Code)) |
| 70 | + if hasattr(notification, 'Message'): |
| 71 | + print("Message {}".format(notification.Message)) |
| 72 | + if hasattr(notification, 'LocalizedMessage'): |
| 73 | + print("LocalizedMessage {}".format(notification.LocalizedMessage)) |
| 74 | + print("") |
| 75 | + |
| 76 | +# Cycle through all the shipping options |
| 77 | +for option in avc_request.response.Options: |
| 78 | + print("Ship Option:") |
| 79 | + if hasattr(option, 'Service'): |
| 80 | + print("Service {}".format(option.Service)) |
| 81 | + if hasattr(option, 'DeliveryDate'): |
| 82 | + print("DeliveryDate {}".format(option.DeliveryDate)) |
| 83 | + if hasattr(option, 'DeliveryDay'): |
| 84 | + print("DeliveryDay {}".format(option.DeliveryDay)) |
| 85 | + if hasattr(option, 'DestinationStationId'): |
| 86 | + print("DestinationStationId {}".format(option.DestinationStationId)) |
| 87 | + if hasattr(option, 'DestinationAirportId'): |
| 88 | + print("DestinationAirportId {}".format(option.DestinationAirportId)) |
| 89 | + if hasattr(option, 'TransitTime'): |
| 90 | + print("TransitTime {}".format(option.TransitTime)) |
| 91 | + print("") |
0 commit comments