Let $$f(z) = \frac{1-e^{|a|iz}}{z^2}$$
and let the contour $C$ be
$$ C = \Gamma_1 \cup \gamma_0 \cup \Gamma_2 \cup \Gamma_R$$

Consider $$\lim_{\epsilon\to0}\oint_C f(z) \, dz = -\pi i \,\text{res}_{z=0} f(z)$$
$$\begin{aligned}
\int_C f(z)\, dz &= \int_{\Gamma_1}f(z)\,dz+\int_{\gamma_0}f(z)\,dz+\int_{\Gamma_2}f(z)\,dz+\int_{\Gamma_R}f(z)\,dz\\
&= \int_{-R}^{-\epsilon} \frac{1-\cos ax}{x^2}\,dx+\int_{\epsilon}^{R} \frac{1-\cos ax}{x^2}\,dx \\ & -i\int_{-R}^{-\epsilon}\frac{\sin |a|x}{x^2}\,dx-i\int_{\epsilon}^R\frac{\sin |a|x}{x^2}\,dx
+\int_{\gamma_0} f(z)\,dz + \int_{\Gamma_R} f(z)\,dz\end{aligned}$$
The integrand of the third and fourth integrals is odd, so that the sum of these integrals is zero.
The integral of $\Gamma_R$ can be bounded as follows:
$$\left|\int_{\Gamma_R} f(z) \,dz \right|\le \int_{0}^\pi \left| \frac{1+e^{-|a|R\sin\theta}}{R^2} \,R\,\right| d\theta < 2\int_{0}^{\pi/2} \left| \frac{1+e^{-\frac{2|a|R \theta}{\pi}}}{R^2} \,R\,\right| d\theta<\frac{2\pi}{R} \to 0, \text{ as } R\to \infty.%\quad (\text{for }\theta>0, 1+e^{-\frac{|a|R\theta}{2}}<2)%$$
So, let $R\to \infty$ and $\epsilon \to 0$, and
$$\displaystyle \int_{-\infty}^\infty \frac{1-\cos a x}{x^2} = \pi i \, \text{res}_{z=0} \frac{1 - e^{|a|iz}}{z^2}= -\pi i \, \text{res}_{z=0} \frac{|a|iz + \frac{(|a|i z)^2}{2!}+\frac{(|a|i z)^3}{3!}+\cdots}{z^2}=\pi |a|$$