public static EndpointDescription select(EndpointDescription[] endpoints, String url)
      throws ServiceResultException {
    // Use best endpoint of the same uri
    EndpointDescription[] endpointsOfTheSameUri =
        EndpointUtil.select(endpoints, url, null, null, null, null);
    if (endpointsOfTheSameUri.length > 0) {
      return select(endpointsOfTheSameUri);
    }

    // Use best endpoint of the same scheme
    String scheme = UriUtil.getTransportProtocol(url);
    EndpointDescription[] endpointsOfTheSameScheme =
        EndpointUtil.select(endpoints, null, scheme, null, null, null);
    if (endpointsOfTheSameScheme.length > 0) {
      return select(endpointsOfTheSameScheme);
    }

    // Just choose one endpoint
    return select(endpoints);
  }