Initial Search
Begin by creating an Atlas object as above, and then create an Address Search Request object that contains your address:
' Set up the request
Dim oRequest As New HpwSoap.AddressSearchRequest
oRequest.Input1 = txtInput.Lines(0)
oRequest.Input2 = txtInput.Lines(1)
oRequest.Input3 = txtInput.Lines(2)
oRequest.Input4 = txtInput.Lines(3)
oRequest.Input5 = txtInput.Lines(4)
...
The above assumes the address you want to search for has been typed into a multi-line text box named txtInput.
To search for this address against your default dataset and using the default options, call the Address Search method, passing in the Address Search Request object and storing the return value in an Address Search Response object:
' Do the lookup
Dim oResponse As HpwSoap.AddressSearchResponse = oAtlas.AddressSearch(oRequest)
The Address Search Response object contains an array of Match Type objects, along with a status code and description.
For Each oMatchType In oResponse.Match
MsgBox(oMatchType.SID & ", " & oMatchType.Text)
Next
' Status
If oResponse.StatusCode > 0 Then
MsgBox(oResponse.StatusDesc)
End If
You will most likely want to display the matches in a tree, list or grid but here we are just displaying them in a message box for simplicity.
If there is a problem, for example if the token username or token password is incorrect, an exception will be thrown. The exception message will contain information about the cause of the problem:
Try
... ' all of the code above
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
Drill down
If a match has further information available, its Expandable property will be Yes. For example, a matching street could be expanded to show the premises on that street, or a matching district could be expanded to show streets within that district.
To get these details for a match, begin by creating an Atlas object as above, and then create an Address Expand Request object that contains the SID of the match you want details for:
' Set up the request
Dim oRequest As New HpwSoap.AddressExpandRequest
oRequest.SID = oMatchType.SID
Now you can call the Address Expand method, passing in the Address Expand Request object and storing the result in an Address Expand Response object:
' Do the lookup
Dim oResponse As HpwSoap.AddressExpandResponse = oAtlas.AddressExpand(oRequest)
Like the Address Search Response, the Address Expand Response object also contains an array of Match Type objects, along with a status code and description.
For Each oMatchType In oResponse.Match
MsgBox(oMatchType.SID & ", " & oMatchType.Text)
Next
' Status
If oResponse.StatusCode > 0 Then
MsgBox(oResponse.StatusDesc)
End If
Again, you will most likely want to display the matches in a tree, list or grid but here we are just displaying them in a message box for simplicity.
Final Selection
To get the address details for a Match Type, begin by creating an Atlas object as above, and then create an Address Details Request object that contains the SID of the match you want details for:
' Set up the request
Dim oRequest As New HpwSoap.AddressdetailsRequest
oRequest.SID = oMatchType.SID
Now you can call the Address Details method, passing in the Address Details Request object and storing the result in an Address Details Response object:
' Do the lookup
Dim oResponse As HpwSoap.AddressDetailsResponse = oAtlas.AddressDetails(oRequest)
The Address Details Response object contains an array of matching Address objects, along with a status code and description.
For Each oMatchType In oResponse.Match
If Not oMatchType.Address Is Nothing Then
Dim oAddress As HpwSoap.addressType = oMatchType.Address
MsgBox(oAddress.Department & vbCrLf & _
oAddress.Organisation & vbCrLf & _
oAddress.Line1 & vbCrLf & _
oAddress.Line2 & vbCrLf & _
oAddress.Line3 & vbCrLf & _
...
oAddress.Town & vbCrLf & _
oAddress.County & vbCrLf & _
oAddress.Postcode)
End If
Next
' Status
If oResponse.StatusCode > 0 Then
MsgBox(oResponse.StatusDesc)
End If
If you requested a Formatted Label (see below), the Address Details Response object will also contain an array of Formatted Label objects.
For Each oMatchType In oResponse.Match
If Not oMatchType.FormattedLabel Is Nothing Then
If (oMatchType.FormattedLabel.status = HpwSoap.statusString.ok) Or _
(oMatchType.FormattedLabel.status = HpwSoap.statusString.split_element) Then
Dim oLabel As HpwSoap.formattedLabelType = oMatchType.FormattedLabel
MsgBox(oLabel.Line1 & vbCrLf & _
oLabel.Line2 & vbCrLf & _
oLabel.Line3 & vbCrLf & _
oLabel.Line4 & vbCrLf & _
oLabel.Line5 & vbCrLf & _
...
)
End If
End If
Next
' Status
If oResponse.StatusCode > 0 Then
MsgBox(oResponse.StatusDesc)
End If
You will most likely want to display the matching addresses in a list or a grid but here we are just displaying them in a message box for simplicity.