Skip to content

Commit 504663f

Browse files
committed
added more example detail for location service
1 parent dce689f commit 504663f

File tree

1 file changed

+51
-19
lines changed

1 file changed

+51
-19
lines changed

examples/location_request.py

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/usr/bin/env python
22
"""
33
This example shows how to use the FedEx Location 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
4+
The variables populated below represents minimum required values as
5+
well as those that are optional. Read comments for details.
6+
You will need to specify all required fields, or risk
7+
seeing a SchemaValidationError
68
exception thrown by suds.
79
810
"""
@@ -21,18 +23,49 @@
2123
customer_transaction_id = "*** LocationService Request v3 using Python ***" # Optional transaction_id
2224
location_request = FedexSearchLocationRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id)
2325

24-
# Specify the type of search and search criteria.
25-
location_request.LocationsSearchCriterion = 'PHONE_NUMBER'
26-
location_request.PhoneNumber = '4169297819'
27-
location_request.MultipleMatchesAction = 'RETURN_ALL'
26+
# Un-comment to specify the type of search and search criteria.
27+
# Can be ADDRESS (default), GEOGRAPHIC_COORDINATES, or PHONE_NUMBER
28+
# location_request.LocationsSearchCriterion = 'PHONE_NUMBER'
2829

29-
# Set constraints, see SearchLocationConstraints definition.
30-
# For LocationTypesToInclude, see FedExLocationType definition.
31-
location_request.Constraints.LocationTypesToInclude = ['FEDEX_SELF_SERVICE_LOCATION',
32-
'FEDEX_AUTHORIZED_SHIP_CENTER']
30+
# Un-comment when using PHONE_NUMBER search criterion.
31+
# location_request.PhoneNumber = '4169297819'
3332

34-
location_request.Address.PostalCode = '38119'
35-
location_request.Address.CountryCode = 'US'
33+
# Un-comment when using GEOGRAPHIC_COORDINATES search criterion.
34+
# location_request.GeographicCoordinates = '43.6357-79.5373'
35+
36+
# Un-comment to specify how to handle multiple matches.
37+
# Can be set to RETURN_ALL (default), RETURN_ERROR, or RETURN_FIRST
38+
# location_request.MultipleMatchesAction = 'RETURN_FIRST'
39+
40+
41+
# Un-comment to specify FedExLocationType constraint, see FedExLocationType definition.
42+
# Can be set to FEDEX_AUTHORIZED_SHIP_CENTER, FEDEX_EXPRESS_STATION, FEDEX_FREIGHT_SERVICE_CENTER,
43+
# FEDEX_GROUND_TERMINAL, FEDEX_HOME_DELIVERY_STATION, FEDEX_OFFICE, FEDEX_SELF_SERVICE_LOCATION,
44+
# FEDEX_SHIPSITE, or FEDEX_SMART_POST_HUB
45+
# location_request.Constraints.LocationTypesToInclude = ['FEDEX_SELF_SERVICE_LOCATION',
46+
# 'FEDEX_AUTHORIZED_SHIP_CENTER']
47+
48+
# Un-comment to to set a maximum radius for location query.
49+
# This really can narrow down the location results but is not required.
50+
location_request.Constraints.RadiusDistance.Value = 1.5
51+
location_request.Constraints.RadiusDistance.Units = "KM" # KM or MI
52+
53+
# Un-comment to specify supported redirect to hold services. Only
54+
# supported by certain countries,from testing only US is supported.
55+
# Can be FEDEX_EXPRESS, FEDEX_GROUND, or FEDEX_GROUND_HOME_DELIVERY
56+
# location_request.Constraints.SupportedRedirectToHoldServices = "FEDEX_GROUND"
57+
58+
# Required even if using phone number search
59+
location_request.Address.PostalCode = 'M5V 1Z0'
60+
location_request.Address.CountryCode = 'CA'
61+
62+
# Un-comment to set sort criteria. By default Matching locations sorted by
63+
# DISTANCE and LOWEST_TO_HIGHEST if no sort criteria is specified.
64+
# Crieterion can be LATEST_EXPRESS_DROPOFF_TIME, LATEST_GROUND_DROPOFF_TIME,
65+
# LOCATION_TYPE or DISTANCE (default)
66+
# Order can be LOWEST_TO_HIGHEST (default) or HIGHEST_TO_LOWEST
67+
# location_request.SortDetail.Criterion = 'LATEST_GROUND_DROPOFF_TIME'
68+
# location_request.SortDetail.Order = 'LOWEST_TO_HIGHEST'
3669

3770
# If you'd like to see some documentation on the ship service WSDL, un-comment
3871
# this line. (Spammy).
@@ -66,12 +99,11 @@
6699
print("ResultsReturned: {}".format(location_request.response.ResultsReturned))
67100

68101
result = location_request.response.AddressToLocationRelationships[0]
69-
print("MatchedAddress: {}, {} Residential: {}".format(result.MatchedAddress.PostalCode,
70-
result.MatchedAddress.CountryCode,
71-
result.MatchedAddress.Residential))
102+
print("MatchedAddress: {}, {} Residential: {}".format(getattr(result.MatchedAddress, 'PostalCode', ''),
103+
getattr(result.MatchedAddress, 'CountryCode', ''),
104+
getattr(result.MatchedAddress, 'Residential', '')))
72105
print("MatchedAddressGeographicCoordinates: {}".format(result.MatchedAddressGeographicCoordinates.strip("/")))
73106

74-
# Locations sorted by closest found to furthest.
75107
locations = result.DistanceAndLocationDetails
76108
for location in locations:
77109
print("Distance: {}{}".format(location.Distance.Value, location.Distance.Units))
@@ -85,14 +117,14 @@
85117
contact_and_address = sobject_to_dict(contact_and_address)
86118
print("LocationContactAndAddress Dict: {}".format(contact_and_address))
87119

88-
print("GeographicCoordinates {}".format(getattr(location_detail, 'GeographicCoordinates')))
89-
print("LocationType {}".format(getattr(location_detail, 'LocationType')))
120+
print("GeographicCoordinates {}".format(getattr(location_detail, 'GeographicCoordinates', '')))
121+
print("LocationType {}".format(getattr(location_detail, 'LocationType', '')))
90122

91123
if hasattr(location_detail, 'Attributes'):
92124
for attribute in location_detail.Attributes:
93125
print("Attribute: {}".format(attribute))
94126

95-
print("MapUrl {}".format(getattr(location_detail, 'MapUrl')))
127+
print("MapUrl {}".format(getattr(location_detail, 'MapUrl', '')))
96128

97129
if hasattr(location_detail, 'NormalHours'):
98130
for open_time in location_detail.NormalHours:

0 commit comments

Comments
 (0)