|
| 1 | +#!/usr/bin/env python |
| 2 | +""" |
| 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 |
| 7 | +exception thrown by suds. |
| 8 | +""" |
| 9 | +import logging |
| 10 | +import datetime |
| 11 | +from example_config import CONFIG_OBJ |
| 12 | +from fedex.services.availability_commitment_service import FedexAvailabilityCommitmentRequest |
| 13 | + |
| 14 | +# Set this to the INFO level to see the response from Fedex printed in stdout. |
| 15 | +logging.basicConfig(level=logging.INFO) |
| 16 | + |
| 17 | + |
| 18 | +# This is the object that will be handling our service availability request. |
| 19 | +# We're using the FedexConfig object from example_config.py in this dir. |
| 20 | +customer_transaction_id = "*** AvailabilityAndCommitment Request v4 using Python ***" # Optional transaction_id |
| 21 | +avc_request = FedexAvailabilityCommitmentRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id) |
| 22 | + |
| 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' |
| 26 | + |
| 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' |
| 30 | + |
| 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' |
| 33 | + |
| 34 | +# Can be set to the expected date. Defaults to today if not set. |
| 35 | +#avc_request.ShipDate = datetime.date.today().isoformat() |
| 36 | + |
| 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' |
| 39 | + |
| 40 | +# Fires off the request, sets the 'response' attribute on the object. |
| 41 | +avc_request.send_request() |
| 42 | + |
| 43 | +# If you'd like to see some documentation on the ship service WSDL, un-comment this line. |
| 44 | +print(avc_request.client) |
| 45 | + |
| 46 | +# Un-comment this to see your complete, ready-to-send request as it stands |
| 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 |
| 56 | +# attributes through the response attribute on the request object. This is |
| 57 | +# good to un-comment to see the variables returned by the FedEx reply. |
| 58 | +print(avc_request.response) |
| 59 | + |
| 60 | +# Here is the overall end result of the query. |
| 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