Skip to content

Commit ecbc924

Browse files
author
Greg Taylor
committed
More commenting and details in the create_shipment.py example.
1 parent 5a96034 commit ecbc924

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

examples/create_shipment.py

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,91 +19,99 @@
1919
use_test_server=True)
2020

2121
# This is the object that will be handling our tracking request.
22-
ship = FedexProcessShipmentRequest(config_obj)
22+
shipment = FedexProcessShipmentRequest(config_obj)
2323

2424
# This is very generalized, top-level information.
2525
# REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER or STATION
26-
ship.RequestedShipment.DropoffType = 'REGULAR_PICKUP'
26+
shipment.RequestedShipment.DropoffType = 'REGULAR_PICKUP'
2727

2828
# See page 355 in WS_ShipService.pdf for a full list. Here are the common ones:
2929
# STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, FEDEX_EXPRESS_SAVER
30-
ship.RequestedShipment.ServiceType = 'PRIORITY_OVERNIGHT'
30+
shipment.RequestedShipment.ServiceType = 'PRIORITY_OVERNIGHT'
3131

3232
# What kind of package this will be shipped in.
3333
# FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING
34-
ship.RequestedShipment.PackagingType = 'FEDEX_PAK'
34+
shipment.RequestedShipment.PackagingType = 'FEDEX_PAK'
3535

3636
# No idea what this is.
3737
# INDIVIDUAL_PACKAGES, PACKAGE_GROUPS, PACKAGE_SUMMARY
38-
ship.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES'
38+
shipment.RequestedShipment.PackageDetail = 'INDIVIDUAL_PACKAGES'
3939

4040
# Shipper contact info.
41-
ship.ShipperContact.PersonName = 'Sender Name'
42-
ship.ShipperContact.CompanyName = 'Some Company'
43-
ship.ShipperContact.PhoneNumber = '9012638716'
41+
shipment.ShipperContact.PersonName = 'Sender Name'
42+
shipment.ShipperContact.CompanyName = 'Some Company'
43+
shipment.ShipperContact.PhoneNumber = '9012638716'
4444

4545
# Shipper address.
46-
ship.ShipperAddress.StreetLines = ['Address Line 1']
47-
ship.ShipperAddress.City = 'Herndon'
48-
ship.ShipperAddress.StateOrProvinceCode = 'VA'
49-
ship.ShipperAddress.PostalCode = '20171'
50-
ship.ShipperAddress.CountryCode = 'US'
51-
ship.ShipperAddress.Residential = True
46+
shipment.ShipperAddress.StreetLines = ['Address Line 1']
47+
shipment.ShipperAddress.City = 'Herndon'
48+
shipment.ShipperAddress.StateOrProvinceCode = 'VA'
49+
shipment.ShipperAddress.PostalCode = '20171'
50+
shipment.ShipperAddress.CountryCode = 'US'
51+
shipment.ShipperAddress.Residential = True
5252

5353
# Recipient contact info.
54-
ship.RecipientContact.PersonName = 'Recipient Name'
55-
ship.RecipientContact.CompanyName = 'Recipient Company'
56-
ship.RecipientContact.PhoneNumber = '9012637906'
54+
shipment.RecipientContact.PersonName = 'Recipient Name'
55+
shipment.RecipientContact.CompanyName = 'Recipient Company'
56+
shipment.RecipientContact.PhoneNumber = '9012637906'
5757

5858
# Recipient address
59-
ship.RecipientAddress.StreetLines = ['Address Line 1']
60-
ship.RecipientAddress.City = 'Herndon'
61-
ship.RecipientAddress.StateOrProvinceCode = 'VA'
62-
ship.RecipientAddress.PostalCode = '20171'
63-
ship.RecipientAddress.CountryCode = 'US'
59+
shipment.RecipientAddress.StreetLines = ['Address Line 1']
60+
shipment.RecipientAddress.City = 'Herndon'
61+
shipment.RecipientAddress.StateOrProvinceCode = 'VA'
62+
shipment.RecipientAddress.PostalCode = '20171'
63+
shipment.RecipientAddress.CountryCode = 'US'
6464
# This is needed to ensure an accurate rate quote with the response.
65-
ship.RecipientAddress.Residential = True
65+
shipment.RecipientAddress.Residential = True
6666

6767
# RECIPIENT, SENDER or THIRD_PARTY
68-
ship.ShippingChargesPayment.PaymentType = 'SENDER'
68+
shipment.ShippingChargesPayment.PaymentType = 'SENDER'
6969

7070
# These are example label values. You'll want to adjust these to fit your
7171
# usage case.
72-
ship.LabelSpecification.LabelFormatType = 'COMMON2D'
73-
ship.LabelSpecification.ImageType = 'PNG'
74-
ship.LabelSpecification.LabelStockType = 'PAPER_7X4.75'
72+
shipment.LabelSpecification.LabelFormatType = 'COMMON2D'
73+
shipment.LabelSpecification.ImageType = 'PNG'
74+
shipment.LabelSpecification.LabelStockType = 'PAPER_7X4.75'
7575

76-
package1_weight = ship.create_wsdl_object_of_type('Weight')
76+
package1_weight = shipment.create_wsdl_object_of_type('Weight')
7777
# Weight, in pounds.
7878
package1_weight.Value = 1.0
7979
package1_weight.Units = "LB"
8080

81-
package1 = ship.create_wsdl_object_of_type('RequestedPackageLineItem')
81+
package1 = shipment.create_wsdl_object_of_type('RequestedPackageLineItem')
8282
package1.Weight = package1_weight
8383
#print package1
8484

85-
ship.add_package(package1)
85+
shipment.add_package(package1)
8686

8787
# If you'd like to see some documentation on the ship service WSDL, un-comment
8888
# this line. (Spammy).
89-
#print ship.client
89+
#print shipment.client
9090

9191
# Un-comment this to see your complete, ready-to-send request as it stands
9292
# before it is actually sent. This is useful for seeing what values you can
9393
# change.
94-
#print ship.RequestedShipment
94+
#print shipment.RequestedShipment
9595

9696
# Fires off the request, sets the 'response' attribute on the object.
97-
ship.send_request()
97+
shipment.send_request()
9898

9999
# This will show the reply to your shipment being sent. You can access the
100-
# attributes through the response attribute on the request object.
101-
print ship.response
100+
# attributes through the response attribute on the request object. This is
101+
# good to un-comment to see the variables returned by the Fedex reply.
102+
#print shipment.response
103+
104+
# Here is the overall end result of the query.
105+
print "HighestSeverity:", shipment.response.HighestSeverity
106+
# Getting the tracking number from the new shipment.
107+
print "Tracking #:", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].TrackingIds[0].TrackingNumber
108+
# Net shipping costs.
109+
print "Net Shipping Cost (US$):", shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].PackageRating.PackageRateDetails[0].NetCharge.Amount
102110

103111
# Get the label image in ASCII format from the reply. Note the list indices
104112
# we're using. You'll need to adjust or iterate through these if your shipment
105113
# has multiple packages.
106-
ascii_label_data = ship.response.CompletedShipmentDetail.CompletedPackageDetails[0].Label.Parts[0].Image
114+
ascii_label_data = shipment.response.CompletedShipmentDetail.CompletedPackageDetails[0].Label.Parts[0].Image
107115
# Convert the ASCII data to binary.
108116
label_binary_data = binascii.a2b_base64(ascii_label_data)
109117

0 commit comments

Comments
 (0)