|
1 | 1 | #!/usr/bin/env python |
2 | 2 | """ |
3 | 3 | 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 |
6 | 8 | exception thrown by suds. |
7 | 9 |
|
8 | 10 | """ |
|
21 | 23 | customer_transaction_id = "*** LocationService Request v3 using Python ***" # Optional transaction_id |
22 | 24 | location_request = FedexSearchLocationRequest(CONFIG_OBJ, customer_transaction_id=customer_transaction_id) |
23 | 25 |
|
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' |
28 | 29 |
|
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' |
33 | 32 |
|
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' |
36 | 69 |
|
37 | 70 | # If you'd like to see some documentation on the ship service WSDL, un-comment |
38 | 71 | # this line. (Spammy). |
|
66 | 99 | print("ResultsReturned: {}".format(location_request.response.ResultsReturned)) |
67 | 100 |
|
68 | 101 | 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', ''))) |
72 | 105 | print("MatchedAddressGeographicCoordinates: {}".format(result.MatchedAddressGeographicCoordinates.strip("/"))) |
73 | 106 |
|
74 | | -# Locations sorted by closest found to furthest. |
75 | 107 | locations = result.DistanceAndLocationDetails |
76 | 108 | for location in locations: |
77 | 109 | print("Distance: {}{}".format(location.Distance.Value, location.Distance.Units)) |
|
85 | 117 | contact_and_address = sobject_to_dict(contact_and_address) |
86 | 118 | print("LocationContactAndAddress Dict: {}".format(contact_and_address)) |
87 | 119 |
|
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', ''))) |
90 | 122 |
|
91 | 123 | if hasattr(location_detail, 'Attributes'): |
92 | 124 | for attribute in location_detail.Attributes: |
93 | 125 | print("Attribute: {}".format(attribute)) |
94 | 126 |
|
95 | | - print("MapUrl {}".format(getattr(location_detail, 'MapUrl'))) |
| 127 | + print("MapUrl {}".format(getattr(location_detail, 'MapUrl', ''))) |
96 | 128 |
|
97 | 129 | if hasattr(location_detail, 'NormalHours'): |
98 | 130 | for open_time in location_detail.NormalHours: |
|
0 commit comments