  We develop and test a new statistical method to measure the kinematic
Sunyaev-Zel'dovich (kSZ) effect. A sample of independently detected clusters is
combined with the cosmic flow field predicted from a galaxy redshift survey in
order to derive a matched filter that optimally weights the kSZ signal for the
sample as a whole given the noise involved in the problem. We apply this
formalism to realistic mock microwave skies based on cosmological $N$-body
simulations, and demonstrate its robustness and performance. In particular, we
carefully assess the various sources of uncertainty, cosmic microwave
background primary fluctuations, instrumental noise, uncertainties in the
determination of the velocity field, and effects introduced by miscentring of
clusters and by uncertainties of the mass-observable relation (normalization
and scatter). We show that available data (\plk\ maps and the MaxBCG catalogue)
should deliver a $7.7\sigma$ detection of the kSZ. A similar cluster catalogue
with broader sky coverage should increase the detection significance to $\sim
13\sigma$. We point out that such measurements could be binned in order to
study the properties of the cosmic gas and velocity fields, or combined into a
single measurement to constrain cosmological parameters or deviations of the
law of gravity from General Relativity.
