Discovery
To discover what Extra Data is available for a dataset, begin by creating an Atlas object as above, and then create an Extra Data Request object that contains the dataset you want to enquire:
' Set up the request
Dim oRequest As New HpwSoap.ExtraDataRequest
oRequest.MAF = "uk-rm-paf-internal"
The above assumes the dataset you want to use is the UK Royal Mail PAF.
Now you can call the Extra Data method, passing in the Extra Data Request object and storing the return value in an Extra Data Response object:
' Do the lookup
Dim oResponse As HpwSoap.ExtraDataResponse = oAtlas.extraData(oRequest)
The Extra Data Response object contains an array of Extra Data fields you can request, along with a status code and description.
lstExtraData.Items.Clear()
If Not oResponse.ExtraData Is Nothing Then
For Each s In oResponse.ExtraData
lstExtraData.Items.Add(s)
Next
End If
' Status
If oResponse.StatusCode > 0 Then
MsgBox(oResponse.StatusDesc)
End If
The above assumes you want to display the fields in a list box.
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
Request
Now that you have discovered what Extra Data is available you can request some or all of this data to be returned with your postcode lookups.
You can specify an array of Extra Data field names in the Extra Data property of the Postcode Lookup Request object.
If lstExtraData.CheckedItems.Count > 0 Then
Dim extraData As New List(Of String)
For Each o In lstExtraData.CheckedItems
extraData.Add(o)
Next
oRequest.ExtraData = extraData.ToArray()
End If
The above assumes you want to request those fields that have been checked in a list box.
Retrieval
When processing your Postcode Lookup Response, you can check each Match Type for the existence of an Extra Data Record and then retrieve all the items contained within:
If Not oMatchType.ExtraDataRecord Is Nothing Then
For Each oExtraDataRecordType In oMatchType.ExtraDataRecord
For Each oExtraDataRecordItemType In oExtraDataRecordType.Item
If Not oExtraDataRecordItemType.Value Is Nothing Then
MsgBox(oExtraDataRecordItemType.Value)
End If
Next
Next
End If