Server Side Sorting

Request that the server sort results before returning them to the client. See RFC 2891. The SortKey class accepts three parameters that control the sorting:

SearchOperation search = new SearchOperation(new DefaultConnectionFactory("ldap://directory.ldaptive.org"));
SearchRequest request = SearchRequest.builder()
  .dn("dc=ldaptive,dc=org")
  .filter("(givenName=d*)")
  .returnAttributes("cn", "sn")
  .controls(new SortRequestControl(new SortKey[] {new SortKey("sn", "caseExactMatch")}, true)) // sort by surname
  .build();
SearchResponse response = search.execute(request);
for (LdapEntry entry : response.getEntries()) {
  // do something useful with the entry
}